package org.bt.common.validator.sign;

import org.bt.common.validator.aspect.Positive;
import org.bt.common.validator.number.InfinityNumberComparatorHelper;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Check that the number being validated is positive.
 *
 * @author tongw
 */
public class PositiveValidatorForDouble implements ConstraintValidator<Positive, Double> {

    @Override
    public boolean isValid(Double value, ConstraintValidatorContext context) {
        // null values are valid
        if (value == null) {
            return true;
        }

        return NumberSignHelper.signum(value, InfinityNumberComparatorHelper.LESS_THAN) > 0;
    }
}
